package com.djsearch.adapter;

import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.djsearch.R;
import com.djsearch.bean.GroupBuyGoods;
import com.djsearch.data.ImageManager;
import com.djsearch.data.RequestImage;
import com.djsearch.util.AsyncImageLoader;
import com.djsearch.util.AsyncImageLoader.ImageCallback;
/**
 * 团购商品列表适配器
 * @author chenyang2
 *
 */
public class GroupShopListViewAdapter extends BaseAdapter{
	


	private Context mContext;
	private List<GroupBuyGoods> groupShopGoodsList;
	private Bitmap mbitmap;
	public GroupShopListViewAdapter(Context context,List<GroupBuyGoods> list) {
		mContext = context;
		groupShopGoodsList = list;
		Bitmap bitmap = ImageManager.drawableToBitmap(mContext.getResources().getDrawable(R.drawable.taogou),150.0f);
		mbitmap = (ImageManager.resizeImage(bitmap, 150.0f));
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return groupShopGoodsList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return groupShopGoodsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void refreshData(List<GroupBuyGoods> list) {
		groupShopGoodsList = list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		if (convertView == null) {
			LayoutInflater layoutInflater = ((Activity) mContext).getLayoutInflater();
			convertView = layoutInflater.inflate(R.layout.group_shop_listview_item, parent, false);
			convertView.setTag(convertView);
		} else {
			convertView = (View) convertView.getTag();
		}
		//商品图片
		final ImageView goodsImg = (ImageView)convertView.findViewById(R.id.goodsImg);
		RequestImage.getIntance(mbitmap, "GroupShop").download(groupShopGoodsList.get(position).getSmallImage(), 
				goodsImg);
		//商品所在店铺
		TextView shopName = (TextView)convertView.findViewById(R.id.shopNameText);
		shopName.setText(groupShopGoodsList.get(position).getShopName());
		//距离我的距离
		TextView distance = (TextView)convertView.findViewById(R.id.distanceText);
		distance.setText(groupShopGoodsList.get(position).getShopDistance());
		//是否是团购，标志图
		ImageView groupImg = (ImageView)convertView.findViewById(R.id.groupImg);
		//商品的描述
		TextView goodsDescribe = (TextView)convertView.findViewById(R.id.goodsDescribeText);
		goodsDescribe.setText(groupShopGoodsList.get(position).getShopDescripe());
		//现在价格
		TextView nowPrice = (TextView)convertView.findViewById(R.id.priceText);
		nowPrice.setText("原价:"+groupShopGoodsList.get(position).getShopPrice());
		//现在价格
		TextView oldPrice = (TextView)convertView.findViewById(R.id.oldPriceText);
		oldPrice.setText(groupShopGoodsList.get(position).getSalePrice());
		//地址
		TextView shopPlace = (TextView)convertView.findViewById(R.id.shopPlace);
		shopPlace.setText(groupShopGoodsList.get(position).getShopPlace());
		return convertView;
	}
	
	static class Holder {
		
	}



}
